package cn.edu.lingnan.servlet.project;

import cn.edu.lingnan.pojo.Project;
import cn.edu.lingnan.service.ProjectService;
import cn.edu.lingnan.service.ProjectServiceImp;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/updateproject")
public class UpdateProjectServlet extends HttpServlet {
    private ProjectService projectService= new ProjectServiceImp();

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("UTF-8");
        response.setCharacterEncoding("UTF-8");
        int protectId = Integer.parseInt(request.getParameter("protectId"));
        String projectName = request.getParameter("projectName");
        System.out.println("项目名字"+projectName);
        int postId = Integer.parseInt(request.getParameter("postId"));
        String postName = request.getParameter("postName");
        String type = request.getParameter("type");
        Integer status = Integer.parseInt(request.getParameter("status"));
        String startTime = request.getParameter("startTime");
        String endTime = request.getParameter("endTime");
        String members = request.getParameter("members");
        String description = request.getParameter("description");

       Project project = new Project();
       project.setProtectId(protectId);
       project.setProjectName(projectName);
       project.setPostId(postId);
       project.setPostName(postName);
       project.setType(type);
       project.setStatus(status);
       project.setStartTime(startTime);
       project.setEndTime(endTime);
       project.setMembers(members);
       project.setDescription(description);

     Integer rowsAffected=  projectService.updateProject(project);
        if (rowsAffected > 0) {
            request.setAttribute("message", "项目更新成功!");
            request.setAttribute("messageType", "success");
        } else {
            request.setAttribute("message", "项目更新失败，请重试。");
            request.setAttribute("messageType", "danger");
        }
        request.getRequestDispatcher("/editProject.jsp").forward(request, response);

    }

}